import { reactive, onMounted, ref } from 'vue';
import { getList } from '@/api/table';
import { deepClone } from '@/utils/index';
// 获取数据
export function repositoriesList() {
  // 数据仓库
  const state = reactive({
    dialogType: 'update',
    dialogVisible: false, // 弹窗
    listLoading: true, // 加载状态
    list: [], // 列表数据
    total: 1,
    listQuery: {
      page: 1,
      limit: 10,
    },
  });
  // fetch
  const fetchData = () => {
    state.listLoading = true;
    getList({ page: state.listQuery.page, limit: state.listQuery.limit }).then(response => {
      state.list = response.data.items;
      state.total = response.data.total;
      state.listLoading = false;
    });
  };
  fetchData();
  // 编辑项
  const formModel = {
    author: '',
    display_time: '1986-05-22 07:06:58',
    id: 127100,
    pageviews: 518,
    status: 'draft',
    title: ''
  };
  const form = ref(Object.assign({}, formModel));
  // 搜索项
  const filterItems = {
    author: null
  };
  const filter = ref(Object.assign({}, filterItems));
  // add
  const addData = () => {};
  // update
  const updateData = () => {};
  // delete
  const deleteData = (id) => {};
  return { state, form, filter, fetchData, addData, updateData, deleteData };
}
